package com.taiji.example.service.impl;

import com.taiji.example.domain.User;
import com.taiji.example.domain.UserRepository;
import com.taiji.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @author chenzhe
 * @version 1.0
 * @date 2021/5/26
 * @describe
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public User add(User user) {
        String encode = passwordEncoder.encode(user.getPassword());
        user.setPassword(encode);
        User save = userRepository.save(user);
        return save;
    }

    @Override
    public User addUser(User user) {
        String encode = passwordEncoder.encode(user.getPassword());
        user.setPassword(encode);
        User save = userRepository.save(user);
        System.out.println(save);
        return save;
    }
}
